const Controller = require('egg').Controller;

class HomeController extends Controller {
	async housing() {
		const {
			ctx
		} = this
		const data = await ctx.service.home.housing()
		ctx.body = {
			code: 1,
			data
		}
	}
	async delHousing() {
		const {
			ctx
		} = this
		const data = await ctx.service.home.delHousing()
		if (data.affectedRows >= 1) {
			ctx.body = {
				code: 1,
				message: '删除成功'
			}
		} else {
			ctx.body = {
				code: 0,
				message: '删除失败'
			}
		}
	}
	async addHousing() {
		const {
			ctx
		} = this
		const data = await ctx.service.home.addHousing()
		if (data.affectedRows >= 1) {
			ctx.body = {
				code: 1,
				message: '添加成功'
			}
		} else {
			ctx.body = {
				code: 0,
				message: '添加失败'
			}
		}
	}
	async editHousing() {
		const {
			ctx
		} = this
		const data = await ctx.service.home.editHousing()
		if (data.affectedRows >= 1) {
			ctx.body = {
				code: 1,
				message: '编辑成功'
			}
		} else {
			ctx.body = {
				code: 0,
				message: '编辑失败'
			}
		}
	}
	async editType() {
		const {
			ctx
		} = this;
		const data = await ctx.service.home.editType()
		if (data.affectedRows >= 1) {
			ctx.body = {
				code: 1,
				message: '修改状态成功'
			}
		} else {
			ctx.body = {
				code: 0,
				message: '修改状态失败'
			}
		}
	}
}

module.exports = HomeController;